package com.shujia.moniqiefeng.chuangtongzuofa;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class ClassNumberDemo {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new FileReader("hodoop/data/students.txt"));
        HashMap<String, Long> map = new HashMap<>();
        String line = null;
        while ((line = br.readLine()) != null) {
            String clazz = line.split(",")[4];
            if (map.containsKey(clazz)) {
                map.put(clazz, map.get(clazz) + 1L);
            } else {
                map.put(clazz, 1L);
            }
        }

        Set<Map.Entry<String, Long>> entries = map.entrySet();
        for (Map.Entry<String, Long> entry : entries) {
            String key = entry.getKey();
            Long value = entry.getValue();
            System.out.println(  key + ":" +  value);
        }

    }
}
